package edu.cn.nlsde.tmfst.textCrawler;

import edu.cn.nlsde.tmfst.crawler.handler.handler_TM;
import edu.cn.nlsde.tmfst.model.Comment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by dell on 2016/12/19.
 */
public class TmallCommentCrawler implements CommentCrawler {
    static Logger mylog = LoggerFactory.getLogger(TmallCommentCrawler.class.getName());
    private Pattern p = Pattern.compile("id=([a-z0-9]+)", Pattern.CASE_INSENSITIVE);

    @Override
    public List<Comment> get_Comment_list(String url) {
        List<Comment> list = null;
        long before = System.currentTimeMillis();
        Matcher m = p.matcher(url);
        if (!m.find()) {
            mylog.error("url error, Can't find product id in url. Is this a valid tmall url?");
            return list;
        }
        handler_TM.crawler_comment(url);

        list = Comment.get_comment("Tmall_" + m.group(1));

        mylog.error("#####################" + (System.currentTimeMillis() - before) / 1000 + "############################");
        return list;
    }
}
